
import 'package:Smart/pages/productor008/project/util/gs_call_util.dart';
import 'package:flutter/material.dart';
//屏幕适配
import 'package:Smart/utils/screen_unit/gs_screen_util.dart';
import 'package:Smart/utils/routers/page_jump_service.dart';
import 'package:Smart/res/colors_res.dart';
//颜色配置路径
import 'package:Smart/pages/productor008/project/res/res_colors.dart';
//蓝牙,一键呼叫弹框路径
import 'package:Smart/pages/productor008/project/widget/gs_blecall_dialog.dart';
//弹框中间布局部分
import 'package:Smart/pages/productor008/project/widget/gs_bletxt_widget.dart';
//图标图片配置路径
import 'package:Smart/pages/productor008/project/res/res_url.dart';

class GSIndexPage extends StatefulWidget {
  GSIndexPage({Key key}) : super(key: key);

  @override
  _GSIndexPageState createState() => _GSIndexPageState();
}

class _GSIndexPageState extends State<GSIndexPage> {
 
  List listData = [
    {"title": "一键呼叫"},
    {"title": "主页弹框1"},
    {"title": "主页弹框2"},
    {"title": "主页弹框3"},
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          leading: GestureDetector(
            onTap: () {
              PageJumpService.instance().goBack();
            },
            child: Icon(
              Icons.arrow_back_ios,
              size: 20,
              color: Color(0XFF231815),
            ),
          ),
          backgroundColor: ColorsRes.color_ffffff,
          title: Text(
            "杨情缘- 一键呼叫弹框,蓝牙主页面3弹框",
            style: TextStyle(color: ColorsRes.color_000000),
          ),
        ),
        body: Container(
          margin: EdgeInsets.only(top: 30.w),
          child: ListView.builder(
            itemCount: listData.length,
            itemBuilder: (BuildContext context, int index) {
              return buttonItem(listData[index]["title"], onTap: () {
                itemAction(context, index,"400-820-5555");
              });
            },
          ),
        ));
  }

// container里面buttomItem布局
  Widget buttonItem(String title, {Function onTap}) {
    return ListTile(
      contentPadding: EdgeInsets.all(0),
      title: Container(
        height: 48.w,
        width: 200.w,
        child: Center(
            child: Text(
          title,
          style: TextStyle(color: ResColors.color_141413),
        )),
        color: ResColors.color_D7E600,
      ),
      onTap: onTap,
    );
  }

  // buttomItem的Item对应的弹框事件
  void itemAction(BuildContext context, int index,String phoneNum) {
    switch (index) {
      case 0:
        GSBluetoothCallDialog.showCallAndCancel(
          context,
          message: Container(),
          phoneNum:"$phoneNum",
          onConfirm: ()=>GSCallUtil().tryToCallDialog(context,phoneNum)
        );
        break;
      case 1:
        GSBluetoothCallDialog.showCancelAndConfirm(
          context,
          message: GSBleTxtWidget().blueToothMessageActive(context),
          cancelText: '取消',
          confirmText: '确认开启',
          imagePath: ResUrl.iconImagePath("蓝牙钥匙.png"),//icon_bluetooth.png
          // showCehckbox: false,
        );
        break;
      case 2:
        GSBluetoothCallDialog.showCancelAndConfirm(
          context,
          message: GSBleTxtWidget().blueToothMessageLogin(),
          cancelText: '取消激活',
          confirmText: '继续激活',
          imagePath: ResUrl.iconImagePath("蓝牙钥匙.png"),
          // showCehckbox: false,
        );
        break;
      case 3:
        GSBluetoothCallDialog.showOnlyConfirm(
          context,
          message: GSBleTxtWidget().blueToothMessageUse(context),
          imagePath: ResUrl.iconImagePath("蓝牙钥匙.png"),
          showCehckbox: true,
        );
        break;
    }
  }

}
